﻿using System;
using System.Linq.Expressions;

namespace Shell.PocoDot.Configurations
{
    /// <summary>
    /// 表示一个 PocoDot 的配置信息
    /// </summary>
    public class PocoDotConfiguration
    {
        /// <summary>
        /// 创建一个新的实例
        /// </summary>
        /// <param name="provider">持久化层的配置信息</param>
        /// <param name="pocoDot">PocoDot 的类型</param>
        public PocoDotConfiguration(ProviderConfiguration provider, Type pocoDot)
        {
            this.Provider = provider;
            this.PocoDot = pocoDot;
        }

        /// <summary>
        /// 获取持久化层的配置信息
        /// </summary>
        public ProviderConfiguration Provider { get; private set; }

        /// <summary>
        /// 获取 PocoDot 的类型
        /// </summary>
        public Type PocoDot { get; private set; }

        /// <summary>
        /// 获取当前实例的哈希值
        /// </summary>
        /// <returns>哈希值</returns>
        public override int GetHashCode()
        {
            return this.PocoDot.GetHashCode();
        }
        
        /// <summary>
        /// 决定指定的实例是否与当前实例相同
        /// </summary>
        /// <param name="obj">指定的实例</param>
        /// <returns>判决结果</returns>
        public override bool Equals(object obj)
        {
            var config = obj as PocoDotConfiguration;
            if (config == null)
            {
                return false;
            }
            return config.PocoDot == this.PocoDot && config.Provider == this.Provider;
        }
    }
}
